package com.tx.collections.map;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 */
public class LinkedHashMapDemo {
    public static void main(String[] args) {
        LinkedHashMap map = new LinkedHashMap();
        map.put("hello","world");
        System.out.println(map.get("hello"));
        map.remove("hello");


        testForEach();
    }

    private static void testForEach() {
        //默认访问顺序是按插入顺序来的。
        //如果是按访问顺序，那么先get（"B"）之后,B就在链表的最后尾部了
        //false:结果为ABC  true:结果为ACB
//        LinkedHashMap<String,String> map2 = new LinkedHashMap<>();
        LinkedHashMap<String,String> map2 = new LinkedHashMap<String,String>(16,0.75f,true);
        map2.put("A","1");
        map2.put("B","2");
        map2.put("C","3");
        map2.get("B");
        Set<Map.Entry<String,String>> entrySet = map2.entrySet();
        for(Map.Entry<String,String> entry : entrySet ){
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }
    }
}